package com.hxy.health.platform.service.impl;

import com.hxy.health.platform.dao.UserMapper;
import com.hxy.health.platform.pojo.User;
import com.hxy.health.platform.service.UserService;
import com.hxy.health.platform.utils.MD5Util;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;
    /**
     * 添加用户
     * @param user
     * @return
     */
    @Override
    public int addUser(User user) {
        User  newUser = new User();
        newUser.setEmail(user.getEmail());
        newUser.setPassword(MD5Util.MD5EncodeUtf8(user.getPassword()));
        newUser.setStatus(1);
        newUser.setType(2);
        return userMapper.insertSelective(newUser);
    }

    /**
     * 校验邮箱是否被占用
     * @param email
     * @return
     */
    @Override
    public int verifyEmail(String email) {
        return userMapper.verifyEmail(email);
    }

    /**
     * 用户登录
     * @param user
     * @return
     */
    @Override
    public User userLogin(User user) {
        return userMapper.getByUserEmailAndPassword(user.getEmail(), MD5Util.MD5EncodeUtf8(user.getPassword()));
    }
}
